<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
      <el-form-item>
        <el-select v-model="dataForm.sex" placeholder="请选择性别">
          <el-option v-for="item in options" :key="item.val" :label="item.label" :value="item.val"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.id" placeholder="编号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="search()">查询</el-button>
        <el-button
          v-if="isAuth('partner:teacherinfo:save')"
          type="primary"
          @click="addOrUpdateHandle()"
        >新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" header-align="center" align="center" label="伴学老师编号"></el-table-column>
      <el-table-column prop="name" header-align="center" align="center" label="姓名"></el-table-column>
      <el-table-column prop="headUrl" header-align="center" align="center" label="头像">
        <template slot-scope="scope">
          <img :src="scope.row.headUrl" style="width:40px;height:40px;">
        </template>
      </el-table-column>
      <el-table-column prop="sex" header-align="center" align="center" label="性别">
        <template slot-scope="scope">
          {{scope.row.sex==1?'男生':''}}
          {{ scope.row.sex === 2? '女生': '' }}
          {{ scope.row.sex === 0 ? '未知': '' }}
        </template>
      </el-table-column>
      <el-table-column prop="school" header-align="center" align="center" label="毕业学校"></el-table-column>
      <el-table-column prop="teachingAdd" header-align="center" align="center" label="支教地址 "></el-table-column>
      <el-table-column prop="teachingSchool" header-align="center" align="center" label="支教院校 "></el-table-column>
      <el-table-column prop="teachingGradel" header-align="center" align="center" label="支教年级 "></el-table-column>
      <el-table-column
        prop="teachingStartTime"
        header-align="center"
        align="center"
        label="支教开始时间 "
      ></el-table-column>
      <el-table-column prop="teachingEndTime" header-align="center" align="center" label="支教结束时间"></el-table-column>
      <el-table-column prop="gmtCreated" header-align="center" align="center" label="最后更新时间"></el-table-column>
      <el-table-column prop="gmtUpdate" header-align="center" align="center" label="创建时间"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>
<style>
.active {
  color: #f00;
}
</style>
<script>
import AddOrUpdate from "./teacherinfo-add-or-update";
export default {
  data() {
    return {
      // 性别
      options: [
        {
          val: "0",
          label: "未知"
        },
        {
          val: "1",
          label: "男"
        },
        {
          val: "2",
          label: "女"
        }
      ],
      // 是否开启伴学
      dateSelect: [
        {
          value: "0",
          label: "禁用"
        },
        {
          value: "1",
          label: "开启"
        }
      ],
      dataForm: {
        key: "",
        isAlive:'',
        name:'',
        sex:'',
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    search() {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let obj = {
        page: this.pageIndex,
        limit: this.pageSize,
        key: this.dataForm.key
      };
      if(this.dataForm.sex){
         obj.sex=this.dataForm.sex;
      }
      if(this.dataForm.isAlive){
        obj.isAlive = this.dataForm.isAlive;
      }
      if(this.dataForm.name){
        obj.name = this.dataForm.name;
      }
      this.$http({
        url: this.$http.adornUrl("/partner/teacherinfo/list"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },

    // 删除
  }
};
</script>
